Skip to content

fix(basichost): sort confirmed addrs#3526

Merged
sukunrt merged 1 commit into
masterfrom
fix/autonatv2-sorted-confirmed-addrs
Jul 22, 2026
Merged

fix(basichost): sort confirmed addrs#3526
sukunrt merged 1 commit into
masterfrom
fix/autonatv2-sorted-confirmed-addrs

Conversation

@lidel

@lidel lidel commented Jul 15, 2026

Copy link
Copy Markdown
Member

Problem

AutoNAT v2 keeps a list of the node's addresses that are confirmed reachable from the internet. The list is built in two parts: primary transports (tcp, quic-v1) first, then secondary ones (webrtc-direct, websocket, webtransport). Each part is sorted, but the combined list is not.

The consumer of that list, removeNotInSource, assumes fully sorted input and silently drops entries when it is not. webrtc-direct is the common victim: on a shared UDP port its address sorts before quic-v1, so it lands out of order and gets dropped. ConfirmedAddrs() then says the node is not reachable over webrtc-direct even though AutoNAT just confirmed it was, undoing the inheritance from #3435. Kubo announces confirmed addresses to HTTP routers, so browsers never saw the webrtc-direct address (ipfs/kubo#11369) 🙈

Fix

  • sort the list before returning it from the probe manager
  • experience existential dread
  • add regression tests at two levels; both fail without the fix

Comment thread p2p/host/basic/addrs_reachability_tracker.go Outdated
@sukunrt
sukunrt force-pushed the fix/autonatv2-sorted-confirmed-addrs branch from 42aa212 to 8f56b13 Compare July 22, 2026 15:21
probeManager.AppendConfirmedAddrs emits primary addrs followed by
secondary addrs. Each half is sorted, but the concatenation is not:
a webrtc-direct secondary sorts before its quic-v1 primary on the
same UDP socket.

Both consumers in addrsManager require input sorted by
Multiaddr.Compare: getConfirmedAddrs feeds the buckets to
removeNotInSource, and Addrs() subtracts the unreachable bucket via
removeInSource. Unsorted input makes removeNotInSource silently drop
confirmed addrs, so ConfirmedAddrs() under-reports secondary
transports even though the tracker confirmed them, defeating the
reachability inheritance added in #3435. removeInSource fails the
other way and retains confirmed-unreachable addrs in Addrs().

Sort the buckets in addrsManager.getConfirmedAddrs, next to the
helpers that require the invariant, rather than in the tracker.

Assisted-By: Claude Fable 5
@sukunrt
sukunrt force-pushed the fix/autonatv2-sorted-confirmed-addrs branch from 8f56b13 to 7f0d9b8 Compare July 22, 2026 15:39
@sukunrt
sukunrt merged commit 0d90292 into master Jul 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants